home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / Xconq 7.0d37 / source / kernel / dir.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-17  |  1.7 KB  |  59 lines  |  [TEXT/KAHL]

  1. /* Definitions for directions of the compass.
  2.    Copyright (C) 1987, 88, 89, 91, 92, 93, 1994 Stanley T. Shebs.
  3.  
  4. Xconq is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.  See the file COPYING.  */
  8.  
  9. /* The terrain model is based on hexes arranged in horizontal rows.  This
  10.    means that although east and west remain intact, the concepts of north
  11.    and south have vanished. */
  12.  
  13. /* Unfortunately, not all hex-dependent definitions are here.  Pathfinding
  14.    code has some knowledge of hexes also, as does map generation and
  15.    probably parts of the machine player code. */
  16.  
  17. #define NUMDIRS 6
  18.  
  19. /* Symbols naming the directions. */
  20.  
  21. #define NORTHEAST 0
  22. #define EAST  1
  23. #define SOUTHEAST 2
  24. #define SOUTHWEST 3
  25. #define WEST  4
  26. #define NORTHWEST 5
  27.  
  28. /* String names for the directions. */
  29.          
  30. #define DIRNAMES { "NE", "E", "SE", "SW", "W", "NW" }
  31.  
  32. /* Conversions from directions to x,y deltas. */
  33.  
  34. #define DIRX { 0, 1,  1,  0, -1, -1 }
  35. #define DIRY { 1, 0, -1, -1,  0,  1 }
  36.  
  37. /* Iteration over the different directions. */
  38.  
  39. #define for_all_directions(dir)  for ((dir) = 0; (dir) < NUMDIRS; ++(dir))
  40.  
  41. #define for_all_directions_randomly(dir,tmp)  \
  42.   for ((tmp) = 0, (dir) = xrandom(NUMDIRS); (tmp) < NUMDIRS; ++(tmp), (dir) = ((dir) + 1) % NUMDIRS)
  43.  
  44. /* Formulas for relative directions. */
  45.  
  46. #define left_dir(d) (((d) + 5) % NUMDIRS)
  47.  
  48. #define right_dir(d) (((d) + 1) % NUMDIRS)
  49.  
  50. #define opposite_dir(d) (((d) + 3) % NUMDIRS)
  51.  
  52. /* To generate a random direction. */
  53.  
  54. #define random_dir() (xrandom(NUMDIRS))
  55.  
  56. extern char *dirnames[];
  57.  
  58. extern int dirx[], diry[];
  59.